package com.william.yun.yunliwuli.api.rest;

import com.alibaba.fastjson.JSONObject;
import com.william.yun.yunliwuli.api.HttpResponse;
import com.william.yun.yunliwuli.api.request.gateway.AddGatewayRequest;
import com.william.yun.yunliwuli.api.request.gateway.GatewayRequest;
import com.william.yun.yunliwuli.api.request.gateway.RebootGatewayRequest;
import com.william.yun.yunliwuli.api.response.GatewayResponse;
import com.william.yun.yunliwuli.service.impl.GatewayServiceImpl;

/**
 * ClassName: GatewayApi <br/>
 * Description:  网关 <br/>
 * date: 2021/3/15 9:29<br/>
 *
 * @author william <br/>
 */
public class GatewayApi extends BaseApi {
    /**
     * 查询网关信息
     * @param request
     * @param token
     * @return
     */
    public GatewayResponse gateway(GatewayRequest request, String token){
        JSONObject gateway = new GatewayServiceImpl().getGateway(getJsonParam(request), token);
        return JSONObject.toJavaObject(gateway, GatewayResponse.class);
    }

    /**
     * 添加网关
     * @param request
     * @param token
     * @return
     */
    public HttpResponse addGateway(AddGatewayRequest request,  String token){
        JSONObject jsonObject = new GatewayServiceImpl().insertGateway(getJsonParam(request), token);
        return  JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }

    /**
     * 修改网关
     * @param request
     * @param token
     * @return
     */
    public HttpResponse updateGateway(AddGatewayRequest request,  String token){
        JSONObject jsonObject = new GatewayServiceImpl().updateGateway(getJsonParam(request), token);
        return  JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }
    /**
     * 删除网关
     * @param uuid
     * @param token
     * @return
     */
    public HttpResponse removeGateway(String uuid,  String token){
        JSONObject jsonObject = new GatewayServiceImpl().removeGateway(uuid, token);
        return  JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }


    /**
     * 重启网关
     * @param request
     * @param token
     * @return
     */
    public HttpResponse rebootGateway(RebootGatewayRequest request, String token){
        JSONObject jsonObject = new GatewayServiceImpl().rebootGateway(getJsonParam(request), token);
        return JSONObject.toJavaObject(jsonObject, HttpResponse.class);
    }

}
